/**
 *
 */
package com.angel.dao.generic.actions;

import java.util.Collection;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

import com.angel.dao.generic.interfaces.FindAllInstancesAction;

/**
 * Sorts an entities collection with a order policy for a H generic type.
 * This order policy is a comparator object implemented with a generic type.
 *
 * @author William
 *
 */
public class OrderAllInstancesAction<H extends Object> implements FindAllInstancesAction<H>{

	private Integer priorityLevel;
	private Comparator<H> orderPolicy;

	public OrderAllInstancesAction(Comparator<H> orderPolicy, Integer priorityLevel){
		super();
		this.orderPolicy = orderPolicy;
		this.priorityLevel = priorityLevel;
	}


	public Collection<H> appliesAction(Collection<H> instances) {
		SortedSet<H> sortedCollection = new TreeSet<H>(orderPolicy);
		sortedCollection.addAll(instances);
		return sortedCollection;
	}


	public Integer priorityLevel() {
		return this.priorityLevel;
	}


}
